package com.cskaoyan.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.stereotype.Component;

@Component
public class CountTimeAdvice implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        long start = System.currentTimeMillis();
        Object proceed = methodInvocation.proceed();//执行委托类方法
        long end = System.currentTimeMillis();
        System.out.println(methodInvocation.getMethod().getName() + "方法执行时间：" + (end - start));
        return proceed;
    }
}
